package com.example.util;

import org.hibernate.validator.HibernateValidator;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Set;

public class ValidatorUtils {

	private static final Validator validator = Validation.byProvider(HibernateValidator.class).configure().failFast(true).buildValidatorFactory().getValidator();

	public static <T> Set<ConstraintViolation<T>> validate(T model) {
		return validator.validate(model);
	}

	public static <T> Set<ConstraintViolation<T>> validateProperty(T model, String propertyName) {
		return validator.validateProperty(model, propertyName);
	}
}
